package org.springblade.pm.wrappper;

import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.pm.entity.Contract;
import org.springblade.pm.vo.ContractVo;
import org.springblade.system.feign.IDictClient;

import java.util.ArrayList;
import java.util.List;
public class ContractWrapper extends BaseEntityWrapper<Contract,ContractVo> {

	static IDictClient dictClient;
	static {
		dictClient = SpringUtil.getBean(IDictClient.class);
	}
	public static ContractWrapper build() {
		return new ContractWrapper();
	}

	@Override
	public ContractVo entityVO(Contract entity) {
		ContractVo contractVo = BeanUtil.copy(entity, ContractVo.class);
		R<String> contractStatusName = dictClient.getValue("contract_status", entity.getContractStatus());
		if (contractStatusName.isSuccess()) {
			contractVo.setContractStatusName(contractStatusName.getData());
		}
		return contractVo;
	}

	public List<ContractVo> entityVoList(List<Contract> list) {
		List<ContractVo> contractVoList = new ArrayList<>();
		for (Contract contract : list) {
			contractVoList.add(entityVO(contract));
		}
		return contractVoList;
	}
}
